import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import writerZhuCe from '../components/writer/writerZhuCe.vue'
import writerLogin from '../components/writer/writerLogin.vue'
import writerHome from '../components/writer/writerHome.vue'
import writerWork from '../components/writer/writerWork.vue'
import writerBooks from '../components/writer/writerBooks.vue'
import writerMessage from '../components/writer/writerMessage.vue'
import writerData from '../components/writer/writerData.vue'
import addbook from '../components/books/addbook.vue'
import isbook from '../components/books/isbook.vue'
import tobook from '../components/books/tobook.vue'
import adminLogin from '../components/admin/adminLogin.vue'
import adminHome from '../components/admin/adminHome.vue'
import guanUser from '../components/admin/guanUser.vue'
import guanWriter from '../components/admin/guanWriter.vue'
import guanBook from '../components/admin/guanBook.vue'
import shenhe from '../components/admin/shenhe.vue';
import tuijian from '../components/admin/tuijian.vue';
import thisWriter from "../components/writer/thisWriter.vue"
import guanTitle from '../components/admin/guanTitle.vue'
import readbook from '../components/books/readbook.vue'
import userzhuce from '../components/user/userzhuce.vue'
import userLogin from '../components/user/userLogin.vue'
import bookclass from '../components/books/bookclass.vue'
import thisUser from '../components/user/thisUser.vue'
import userData from '../components/user/userData.vue'
import bookList from '../components/user/bookList.vue'
import userHistory from '../components/user/userHistory.vue'
import comment from '../components/user/comment.vue'
import touser from '../components/user/touser.vue'
import allThisClassBooks from '../components/books/allThisClassBooks.vue'
import searchBook from '../components/books/searchBook.vue'
import bookHome from '../components/books/bookHome.vue'
Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/Home' }, { path: '/thisUser/:id', redirect: '/bookList' }, { path: '/adminHome', redirect: '/guanUser' },
    {
      path: '/writerHome', redirect: '/writerWork' },{ path: '/Home', component: Home },
    { path: '/writerzhuce', component: writerZhuCe }, { path: '/writerlogin', component: writerLogin },
    {
      path: '/writerhome', component: writerHome,
      // beforeEnter: (to, from, next) => {
      //   //const tokenStr = window.localStorage.getItem('writerToken')
      //   //alert(from.path == '/writerlogin')
      //   if (to.path == '/writerhome') {
      //     var tokenStr = window.localStorage.getItem('writerToken')
      //     return next();
      //   }   
      //   if (!tokenStr) {
      //     return next('/writerlogin')
      //   }
      // },
      children: [{ path: '/writerWork', component: writerWork }, { path: '/writerBooks', component: writerBooks },
        { path: '/writerMessage', component: writerMessage }, { path: '/writerData', component: writerData },
        { path: '/addbook', component: addbook }]
    }, { path: '/toWriter/:id', component: thisWriter },
    { path: '/isbook/:id', component: isbook }, { path: '/tobook/:id', component: tobook }, { path: '/readbook/:id/:title', component: readbook },
    { path: '/adminlogin', component: adminLogin },
    { path: '/adminHome', component: adminHome,
      children: [{ path: '/guanUser', component: guanUser }, { path: '/guanWriter', component: guanWriter },
      { path: '/guanBook', component: guanBook }, { path: '/shenhe', component: shenhe },
        { path: '/tuijian', component: tuijian }, { path: '/guanTitle', component: guanTitle }]
    },
    { path: '/userzhuce', component: userzhuce }, { path: "/userLogin", component: userLogin },
    { path: '/bookclass/:id', component: bookclass },
    {
      path: '/thisUser/:id', component: thisUser,
      children: [ { path: '/userData', component: userData },{ path: '/bookList', component:bookList},
      { path: '/userHistory', component: userHistory }, { path: '/comment', component:comment}]
    }, { path: "/touser/:id", component: touser }, { path: "/thisClassBooks/:id", component: allThisClassBooks },
    { path: "/searchBook/:name", component: searchBook},{path:'/bookHome/:name',component:bookHome}
  ]
})
export default router
